package com.five.admin.server.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.five.admin.mapper.IconMapper;
import com.five.admin.server.IconService;
import com.five.pojo.dto.IconQueryDto;
import com.five.pojo.entity.Icon;
import org.springframework.stereotype.Service;

@Service
public class IconServiceImpl extends ServiceImpl<IconMapper, Icon> implements IconService {

    //查询所有和搜所条件
    @Override
    public Page<Icon> findIconByTitle(IconQueryDto iconQueryDto) {
        if (iconQueryDto == null) {
            iconQueryDto = new IconQueryDto();
            // 设置默认值
            iconQueryDto.setPage(1);
            iconQueryDto.setLimit(10);
        }

        Page<Icon> page = new Page<>(iconQueryDto.getPage(), iconQueryDto.getLimit());
        LambdaQueryWrapper<Icon> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(iconQueryDto.getTitle() != null && !iconQueryDto.getTitle()
                .isEmpty(), Icon::getTitle, iconQueryDto.getTitle());
        Page<Icon> iconPage = getBaseMapper().selectPage(page, queryWrapper);
        return iconPage;
    }


}
